package com.mikufufu.blog.config;

import com.mikufufu.blog.common.cache.RedisCache;
import com.mikufufu.blog.common.constant.RedisKey;
import com.mikufufu.blog.service.ArticleService;
import com.mikufufu.blog.service.CategoryService;
import com.mikufufu.blog.service.CommentService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Slf4j
@Configuration
public class InitConfig {

    @Autowired
    private ArticleService articleService;

    @Autowired
    private CategoryService categoryService;

    @Autowired
    private CommentService commentService;

    @Bean
    public void init(){
        log.debug("初始化文章服务");
        RedisCache.set(RedisKey.ARTICLE_COUNT, articleService.count());
        RedisCache.set(RedisKey.WORD_COUNT, articleService.getWordCount());
        log.debug("初始化分类服务");
        RedisCache.set(RedisKey.CATEGORY_COUNT, categoryService.count());
        log.debug("初始化评论服务");
        RedisCache.set(RedisKey.COMMENT_COUNT, commentService.count());
    }
}
